#include <bits/stdc++.h>

int is_in_net(unsigned char *ip, unsigned char *netip, unsigned char *mask)
{
    for (int i = 0; i < 4; i++)
    {
        if ((ip[i] & mask[i]) != (netip[i] & mask[i]))
        {
            return 0;
        }
    }
    return 1;
}

int main()
{
    struct TestCase_IN
    {
        unsigned char ip[4];
        unsigned char netip[4];
        unsigned char mask[4];
        int expected;
    } test_cases_in[] = {
        {{192, 168, 1, 10}, {192, 168, 1, 0}, {255, 255, 255, 0}, 1},  // 匹配
        {{10, 1, 1, 1}, {10, 0, 0, 0}, {255, 0, 0, 0}, 1},             // A类匹配
        {{172, 16, 2, 5}, {172, 16, 0, 0}, {255, 255, 0, 0}, 1},       // B类匹配
        {{192, 168, 3, 5}, {192, 168, 3, 0}, {255, 255, 255, 255}, 0}, // 最后一个字节不匹配
        {{1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, 1}                  // 全零掩码（任意IP都匹配）
    };

    printf("Testing is_in_net():\n");
    for (int i = 0; i < sizeof(test_cases_in) / sizeof(test_cases_in[0]); i++)
    {
        int result = is_in_net(test_cases_in[i].ip, test_cases_in[i].netip, test_cases_in[i].mask);
        // printf("%d\n", result);
        printf("Test %d: %s\n", i + 1, result == test_cases_in[i].expected ? "PASS" : "FAIL");
    }
    return 0;
}